import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/layout_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import '../mypresclist/model/presc_detail_data.dart';
import 'myprescdetail_controller.dart';

class MyprescDetailPage extends GetView<MyPrescDetailController> {
  const MyprescDetailPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: backAppbar(title: "处方详情"),
      body: Padding(
        padding: EdgeInsets.symmetric(horizontal: ScreenHelper.width(15)),
        child: SingleChildScrollView(
          physics: AlwaysScrollableScrollPhysics(),
          child: Column(
            children: [
              divider(),
              Container(
                margin: EdgeInsets.only(top: ScreenHelper.height(10)),
                alignment: Alignment.topCenter,
                child: Text(
                  "阜外华中心血管医院",
                  style: TextStyle(
                      color: AppTheme.dartTextColor,
                      fontSize: ScreenHelper.sp(18),
                      fontWeight: FontWeight.bold),
                ),
              ),
              Container(
                alignment: Alignment.centerRight,
                margin: EdgeInsets.symmetric(vertical: ScreenHelper.height(10)),
                child: Obx(() => Text(
                      "处方单号：${controller.prescDetailData.value.prescription != null ? controller.prescDetailData.value.prescription!.prescriptionNo! : ""}",
                      textAlign: TextAlign.right,
                      style: TextStyle(
                          color: AppTheme.seconddarkWeakTextColor,
                          fontSize: ScreenHelper.sp(15)),
                    )),
              ),
              divider(),
              SizedBox(
                // width: ScreenHelper.screenWidth,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Obx(() => buildTitleItem(
                        str:
                            "姓名：${controller.prescDetailData.value.prescription != null ? controller.prescDetailData.value.prescription!.patientName : ""}")),
                    Obx(() => buildTitleItem(
                        str:
                            "性别：${controller.prescDetailData.value.prescription != null ? controller.prescDetailData.value.prescription!.gender == '1' ? '男' : '女' : ""}")),
                    buildTitleItem(str: "年龄：28岁")
                  ],
                ),
              ),
              SizedBox(
                height: ScreenHelper.height(10),
              ),
              Obx(() => buildInfoItem(
                  attrName: "诊断",
                  rightWidget: Expanded(
                    child: Text(
                      "${controller.prescDetailData.value.prescription != null ? controller.prescDetailData.value.prescription!.diagnosis : ""}",
                      textAlign: TextAlign.end,
                    ),
                  ))),
              buildPrescListView(),
              // Row(
              //   mainAxisAlignment: MainAxisAlignment.end,
              //   children: [
              //     Container(
              //       width: ScreenHelper.width(120),
              //       height: ScreenHelper.height(40),
              //       alignment: Alignment.center,
              //       decoration: BoxDecoration(
              //           color: AppTheme.primyColor,
              //           borderRadius: BorderRadius.circular(10)),
              //       child: GestureDetector(
              //         onTap: () => Get.toNamed(AppRoutes.logistisc),
              //         child: Text(
              //           "物流详情",
              //           style: TextStyle(color: Colors.white),
              //         ),
              //       ),
              //     ),
              //   ],
              // )
            ],
          ),
        ),
      ),
    );
  }

  /// 处方列表
  Widget buildPrescListView() {
    return SizedBox(
      child: GetBuilder<MyPrescDetailController>(
        id: 'drugDetailInfo',
        builder: (controller) => ListView.builder(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (context, index) {
              Drugs drugItem = controller.drugsList[index];
              return buildListItem(drugItem: drugItem);
            },
            itemCount: controller.drugsList.length),
      ),
    );
  }

  /// 处方列表Item
  Widget buildListItem({required Drugs drugItem}) {
    return Card(
      elevation: 0,
      child: Container(
        color: Colors.white,
        padding: EdgeInsets.all(6),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(
                  width: ScreenHelper.width(265),
                  child: Text(
                    "${drugItem.drugName}  ${drugItem.spec} ",
                    style: TextStyle(
                        color: AppTheme.dartTextColor,
                        fontSize: ScreenHelper.sp(14)),
                  ),
                ),
                Text(
                  "¥${drugItem.price}",
                  style: TextStyle(fontSize: ScreenHelper.sp(13)),
                )
              ],
            ),
            Container(
              margin: EdgeInsets.symmetric(vertical: 6),
              child: Text(
                "用法用量：${drugItem.usageCount}，${drugItem.timesCount}，${drugItem.usageDosage},${drugItem.usageDays}",
                style: TextStyle(
                    color: AppTheme.weakTextColor,
                    fontSize: ScreenHelper.sp(14)),
              ),
            ),
            Container(
              margin: EdgeInsets.only(bottom: ScreenHelper.height(10)),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    "x${drugItem.drugCount}盒",
                    style: TextStyle(
                        color: AppTheme.weakTextColor,
                        fontSize: ScreenHelper.sp(15)),
                  ),
                ],
              ),
            ),
            divider(),
          ],
        ),
      ),
    );
  }

  Widget buildTitleItem({required String str}) {
    return Text(
      str,
      style: TextStyle(
          color: AppTheme.dartTextColor, fontSize: ScreenHelper.sp(15)),
    );
  }
}
